/*
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.support.ohos.designlibdemo;

import com.support.ohos.designlibdemo.bean.ListItemBean;
import com.support.ohos.designlibdemo.utils.Cheeses;
import junit.framework.TestCase;
import ohos.aafwk.ability.delegation.AbilityDelegatorRegistry;
import ohos.agp.components.element.Element;
import ohos.agp.utils.Color;
import ohos.app.Context;
import ohos.global.resource.Resource;
import org.junit.Assert;
import org.junit.Test;

import java.util.List;

import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.MatcherAssert.assertThat;

/**
 * CheeseSquare单元测试
 */
public class CheeseSquareTest extends TestCase {

    @Test
    public void testRandomSublist() {
        List<ListItemBean> list = Cheeses.randomSublist(30);
        assertThat(list.size(), is(30));
    }

    @Test
    public void testGetGraphicElement() {
        Context appContext = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
        Element element = Cheeses.getGraphicElement(appContext, ResourceTable.Graphic_bg_detail_item_card_night);
        Assert.assertNotNull(element);
    }

    @Test
    public void testGetColorFromRes() {
        Context appContext = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
        Color color = Cheeses.getColorFromRes(appContext, ResourceTable.Color_detail_text_name_night);
        Assert.assertNotNull(color);
    }

    @Test
    public void testGetResourceFromMedia() {
        Context appContext = AbilityDelegatorRegistry.getAbilityDelegator().getAppContext();
        Resource resource = Cheeses.getResourceFromMedia(appContext, Cheeses.randomCheeseDrawable());
        Assert.assertNotNull(resource);
    }

}